package com.packenius.library.xspdf;

/**
 * Margin of a page.
 * 
 * @author Christian Packenius.
 */
public class XSPageMargin {
  /**
   * Top margin in user units.
   */
  public final double top;

  /**
   * Bottom margin in user units.
   */
  public final double bottom;

  /**
   * Left margin in user units.
   */
  public final double left;

  /**
   * Right margin in user units.
   */
  public final double right;

  /**
   * Horizontal gap between columns.
   */
  public final double columnGapX;

  /**
   * Vertical gap between columns.
   */
  public final double columnGapY;

  /**
   * Constructor.
   * 
   * @param top Top margin.
   * @param bottom Bottom margin.
   * @param left Left margin.
   * @param right Right margin.
   * @param columnGapX Horizontal gap between columns.
   * @param columnGapY Vertical gap between columns.
   */
  public XSPageMargin(double top, double bottom, double left, double right, double columnGapX, double columnGapY) {
    if (top < 0 || bottom < 0 || left < 0 || right < 0) {
      throw new XSPdfException("Margin must be positive or zero!");
    }
    if (columnGapX < 0 || columnGapY < 0) {
      throw new XSPdfException("Gaps must be positive or zero!");
    }
    this.top = top;
    this.bottom = bottom;
    this.left = left;
    this.right = right;
    this.columnGapX = columnGapX;
    this.columnGapY = columnGapY;
  }

  /**
   * Constructor.
   * 
   * @param margin Margin for all sides.
   */
  public XSPageMargin(double margin) {
    this(margin, margin, margin, margin, margin / 2.0, margin / 2.0);
  }

  /**
   * Get sum of left and right margin.
   * 
   * @return Sum of left and right margin.
   */
  public double getLeftRightSum() {
    return left + right;
  }

  /**
   * Get sum of top and bottom margin.
   * 
   * @return Sum of top and bottom margin.
   */
  public double getTopBottomSum() {
    return top + bottom;
  }
}
